<template>
  <div class="content">
    <div class="top">
      <div class="back cubeic-back">
        <router-link to='/ucenter'>返回</router-link>
      </div>
    </div>
    <div class="list">
      <li v-for="(Obj,index) in record" :key="index" @click="recordInfo(Obj)">
        <div class="change">{{typeObj[Obj.type]}}:{{Obj.money}}</div>
        <div class="money">{{Obj.time}}</div>
      </li>
    </div>
  </div>
</template>
<script>
// import store from '@/store'
import { postData } from '../js/axios'
export default {
  data () {
    return {
      email: '',
      userinfo: '',
      record: [],
      typeObj: {}
    }
  },
  methods: {
    recordInfo: function (obj) {
      let remark = ''
      if (obj.remark !== '') {
        remark = obj.remark
      } else {
        remark = '无'
      }
      this.$createDialog({
        type: 'alert',
        content: '备注信息：' + remark
      }).show()
    }
  },
  created () {
    this.userinfo = this.$store.state.userinfo
    this.email = this.userinfo.email
    let Obj = {}
    Obj.userid = this.userinfo.id
    Obj.userid = 1
    if (Obj.userid) {
      postData('http://account-server.localhost/index.php?s=/index/index/moneyrecord', Obj)
        .then(res => {
          console.log('res:', res)
          if (res.code === 'ok') {
            let Obj = {}
            postData('http://account-server.localhost/index.php?s=/index/index/getTypeList', Obj) // 得到类别列表，用于显示
              .then(type => {
                console.log('res:', type)
                if (type.code === 'ok') {
                  let typeList = type.typeList
                  let typeObj = {}
                  for (let i = 0; i < typeList.length; i++) {
                    typeObj[typeList[i].value] = typeList[i].text
                  }
                  console.log(typeObj)
                  this.typeObj = typeObj
                  this.record = res.record
                }
              })
          }
        })
    } else {
      console.log('login-error')
    }
  }
}
</script>
<style lang="stylus" scoped>
.content
  width 100%;
  margin 0 auto;
  position fixed;
  top 0
  bottom 0
  z-index 2
  background #fff;
  .top
    height 40px
    width 100%
    line-height 40px;
    text-align left;
    background rgb(249,124,66)
    .back
      margin-left 15px;
      height 40px;
      width 100px;
      color #fff
    .back a
      color #fff
  .list
    width 100%
    li
      width 100%
      height 40px
      line-height 40px;
      display flex
      justify-content space-between
      padding-left 15px;
      padding-right 15px;
      box-sizing border-box
    li:nth-of-type(even)
      background #eee
    .money
      font-size 14px;

</style>
